<template>
  <view class="tools-home">
    <!-- 顶部导航栏 -->
    <view class="navbar">
      <view class="logo">工具集合</view>
      <view class="search-box">
        <input 
          type="text" 
          placeholder="搜索工具..." 
          v-model="searchKeyword"
          @input="handleSearch"
        />
        <icon type="search" size="18" class="search-icon"></icon>
      </view>
      <!-- 新增退出登录按钮 -->
      <view class="logout-btn" @click="handleLogout">
        <icon type="logout" size="20" class="logout-icon"></icon>
        <text>退出登录</text>
      </view>
    </view>

    <!-- 主要内容区 - 保持不变 -->
    <view class="main-content">
      <!-- 分类标签 -->
      <view class="category-tabs">
        <view 
          v-for="(category, index) in categories" 
          :key="index"
          :class="['tab-item', currentCategory === index ? 'active' : '']"
          @click="switchCategory(index)"
        >
          {{ category.name }}
        </view>
      </view>

      <!-- 工具卡片网格 -->
      <view class="tools-grid">
        <view 
          class="tool-card" 
          v-for="(tool, index) in filteredTools" 
          :key="index"
          @click="navigateToTool(tool.path)"
        >
          <view class="tool-icon">
            <icon :type="tool.icon" size="36"></icon>
          </view>
          <view class="tool-name">{{ tool.name }}</view>
          <view class="tool-desc">{{ tool.description }}</view>
        </view>
        
        <!-- 无结果提示 -->
        <view class="no-result" v-if="filteredTools.length === 0">
          没有找到匹配的工具
        </view>
      </view>
    </view>

    <!-- 页脚 -->
    <view class="footer">
      <view class="copyright">© 2025 象上汇集团 工具集合 | 所有权利保留</view>
    </view>
  </view>
</template>

<script>
import { useStore } from '../../store'
export default {
  data() {
    return {
      // 原有数据保持不变
      searchKeyword: '',
      currentCategory: 0,
      categories: [
        { id: 0, name: '全部工具' },
        { id: 1, name: '排队工具' },
      ],
	  store: useStore(),
      tools: [
        {
          id: 1,
          name: '排队后台',
          description: '排队后台管理系统',
          icon: 'text',
          path: '/pages/Queue/Manager',
          category: 1
        },
        {
          id: 2,
          name: '客流配置',
          description: '管理企业微信客流推送配置',
          icon: 'code',
          path: '/pages/UpdateRole/UpdateRole',
          category: 3
        },
        {
          id: 3,
          name: '消息推送',
          description: '企业微信消息推送手动更改',
          icon: 'image',
          path: '/pages/index/new_file',
          category: 2
        },
		{
		  id: 4,
		  name: '文档管理',
		  description: '企业微信文档查看',
		  icon: 'image',
		  path: '/pages/DocumentList/DocumentList',
		  category: 2
		},
		{
		  id: 5,
		  name: '前厅排队后台',
		  description: '前厅排队后台管理系统',
		  icon: 'image',
		  path: '/pages/QueueFront/Manager',
		  category: 1
		}
      ]
    };
  },
  computed: {
    filteredTools() {
      // 原有逻辑保持不变
      return this.tools.filter(tool => {
        const categoryMatch = this.currentCategory === 0 || tool.category === this.currentCategory;
        const searchMatch = this.searchKeyword === '' || 
          tool.name.toLowerCase().includes(this.searchKeyword.toLowerCase()) ||
          tool.description.toLowerCase().includes(this.searchKeyword.toLowerCase());
        
        return categoryMatch && searchMatch;
      });
    }
  },
  methods: {
    // 原有方法保持不变
    switchCategory(index) {
      this.currentCategory = index;
      uni.pageScrollTo({
        scrollTop: 0,
        duration: 300
      });
    },
    handleSearch() {
      // 可以在这里添加防抖处理
    },
    navigateToTool(path) {
      console.log('跳转到:', path);
      uni.navigateTo({
        url: path
      });
    },
    // 新增退出登录方法
    handleLogout() {
      // 显示确认对话框
      uni.showModal({
        title: '确认退出',
        content: '确定要退出登录吗？',
        success: (res) => {
          if (res.confirm) {
            this.store.logout()
              uni.reLaunch({ url: '/pages/login/login' })
          }
        }
      });
    }
  }
};
</script>

<style scoped>
/* 原有样式保持不变 */
.tools-home {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #f5f7fa;
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 70px;
  background-color: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.logo {
  font-size: 22px;
  font-weight: bold;
  color: #333;
}

.search-box {
  position: relative;
  width: 400px;
}

.search-box input {
  width: 100%;
  height: 40px;
  padding: 0 15px 0 40px;
  border-radius: 20px;
  border: 1px solid #e5e6eb;
  font-size: 14px;
  outline: none;
  transition: all 0.3s;
}

.search-box input:focus {
  border-color: #007aff;
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.2);
}

.search-icon {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
}

/* 新增退出按钮样式 */
.logout-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background-color: #f5f7fa;
  color: #666;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.logout-btn:hover {
  background-color: #e8ebf0;
  color: #333;
}

.logout-icon {
  color: #ff4d4f;
}

/* 主要内容区样式 - 保持不变 */
.main-content {
  flex: 1;
  padding: 30px 50px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}

.category-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 30px;
  overflow-x: auto;
  padding-bottom: 10px;
}

.tab-item {
  padding: 8px 18px;
  background-color: #ffffff;
  border-radius: 20px;
  font-size: 14px;
  color: #666;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.tab-item:hover {
  background-color: #f0f3f9;
  color: #333;
}

.tab-item.active {
  background-color: #007aff;
  color: #ffffff;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 25px;
}

.tool-card {
  background-color: #ffffff;
  border-radius: 10px;
  padding: 25px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.07);
}

.tool-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.tool-icon {
  margin-bottom: 15px;
  color: #007aff;
}

.tool-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #333;
}

.tool-desc {
  font-size: 13px;
  color: #666;
  line-height: 1.5;
}

.no-result {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 0;
  color: #999;
  font-size: 16px;
}

.footer {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #ffffff;
  border-top: 1px solid #eee;
  margin-top: 50px;
}

.copyright {
  font-size: 14px;
  color: #999;
}

/* 响应式调整 - 增加对退出按钮的适配 */
@media (max-width: 1200px) {
  .tools-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}

@media (max-width: 768px) {
  .navbar {
    flex-direction: column;
    height: auto;
    padding: 15px 20px;
    gap: 15px;
  }
  
  .search-box {
    width: 100%;
    margin-top: 0;
  }
  
  .logout-btn {
    align-self: flex-end;
    padding: 6px 12px;
    font-size: 13px;
  }
  
  .main-content {
    padding: 20px 15px;
  }
  
  .tools-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
  }
  
  .tool-card {
    padding: 15px 10px;
  }
  
  .tool-name {
    font-size: 14px;
  }
  
  .tool-desc {
    font-size: 12px;
  }
}
</style>